var data=[
    {cheak:"<input id='check' type='checkbox'>",level:'医疗处置事件',content:'0101',Pinyin:'ZH',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'误诊',content:'0101',Pinyin:'SDFA',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'误治',content:'0101',Pinyin:'SDAAAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'漏诊',content:'0101',Pinyin:'GFQXSDA',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'漏治',content:'0102',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'治疗不当或错误',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'延误误诊',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0102',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
    {cheak:"<input id='check' type='checkbox'>",level:'未执行医疗核心制度',content:'0101',Pinyin:'GAS',strokes:'-',remark:'-'},
]
    var page=1;
    var count=15;
    var tbody=document.querySelector('tbody');
    var oPagination = document.querySelector('.pagination');
    var oPrevBtn = document.querySelector('.prev')
    var oNextBtn = document.querySelector('.next')
    var add=document.querySelector('#add');
    var revise=document.querySelector('#revise');
    var del=document.querySelector('#del');
    var oInputName1=document.querySelector('#InputName1')
    var oInputName2=document.querySelector('#InputName2')
    var oInputName3=document.querySelector('#InputName3')
    var oInquire=document.querySelector('#Inquire')
    var nothing=document.querySelector('#nothing');
    nothing.addEventListener('click',fn7)
    function fn7(){
        oInputName1.value='';
        oInputName2.value='';
        oInputName3.value='';
        render();     
    }
    
    oInquire.addEventListener('click',fn6)
    function fn6(){
        page=1;
        render();
    }
        function render(){
            var str1=oInputName1.value;
            var str2=oInputName2.value;
            var str3=oInputName3.value;
            var all=[];
            var data1=[];
            var data2=[];
            if(str1.trim()==''){
                data1=data;
            }else{
                for(var i=0;i<data.length;i++){
                    if(data[i].content.includes(str1)){
                        data1.push(data[i])
                    }
                }
            }
            if(str2.trim()==''){
                data2=data1;
            }else{
                for(var i=0;i<data1.length;i++){
                    if(data1[i].level.includes(str2)){
                        data2.push(data1[i])
                    }
                }
            }
            if(str3.trim()==''){
                all=data2;
            }else{
                for(var i=0;i<data2.length;i++){
                    if(data2[i].Pinyin.includes(str3)){
                        all.push(data2[i])
                    }
                }
            }
            tbody.innerHTML='';
            var renderAll=all.slice((page - 1) * count, page * count);
        for(var i=0;i<renderAll.length;i++){
            var tr=document.createElement('tr');
            tr.innerHTML=`<td>${renderAll[i].cheak}</td>
            <td>${renderAll[i].level}</td>
            <td>${renderAll[i].content}</td>
            <td>${renderAll[i].Pinyin}</td>
            <td>${renderAll[i].strokes}</td>
            <td>${renderAll[i].remark}</td>`;
            tbody.appendChild(tr);
        }
        var apagebtn=document.querySelectorAll('.pageBtn');
        for(var i=0;i<apagebtn.length;i++){
            oPagination.removeChild(apagebtn[i].parentNode)
        }
    for(var i=1;i<=Math.ceil(all.length/count);i++){
        var oli=document.createElement('li');
        oli.innerHTML=`<a class="pageBtn" href="#">${i}</a>`
        if(i==page){
            oli.className='active';
        }
        oPagination.insertBefore(oli,oPagination.lastElementChild);
    }
        }
    render();
    oPagination.addEventListener('click', changePage);
    function changePage() {
        if (event.target.className == 'pageBtn') {
            page = event.target.innerText;
            render();
        }
    }
    oPrevBtn.addEventListener('click', prev);
    oNextBtn.addEventListener('click', next);
    function prev() {
        if (page > 1) {
            page--;
            render();
        }
    }
    function next() {
        if (page < Math.ceil(data.length / count)) {
            page++;
            render();
        }
    }
    del.addEventListener('click',fn);
    function fn(){
        var check=document.querySelectorAll('#check');
        for(var i=0;i<check.length;i++){
        var a=check[i].checked;
        if(a){
            tbody.removeChild(check[i].parentNode.parentNode)
            data.splice(i,1)
        }
    }
    render();
    }
    var yes=document.querySelector('#yes');
    yes.addEventListener('click',fn2);
    function fn2(){  
        var exampleInputEmail1=document.querySelector('#exampleInputEmail1');
        var exampleInputPassword1=document.querySelector('#exampleInputPassword1');
        var exampleInputPassword2=document.querySelector('#exampleInputPassword2');
        var exampleInputPassword3=document.querySelector('#exampleInputPassword3');
        if(exampleInputEmail1.value==''||exampleInputPassword1.value=='' || exampleInputPassword2.value==''){
            alert('请输入添加内容')
        }else{
        var c={cheak:"<input id='check' type='checkbox'>",
        level:exampleInputPassword1.value,
        content:exampleInputEmail1.value,
        Pinyin:exampleInputPassword2.value,
        strokes:exampleInputPassword3.value,
        remark:'-'}
        data.push(c)
        render()
        }
    }
    revise.addEventListener('click',fn3);
    var divsex=document.querySelector('#tc')
    function fn3(){
        var check=document.querySelectorAll('#check');
        for(var i=0;i<check.length;i++){
            var a=check[i].checked;
            if(a){
             divsex.style.display='block' 
             var exampleInputEmail2=document.querySelector('#exampleInputEmail2');
                var exampleInputPassword4=document.querySelector('#exampleInputPassword4');
                var exampleInputPassword5=document.querySelector('#exampleInputPassword5');
                var exampleInputPassword6=document.querySelector('#exampleInputPassword6');
                exampleInputEmail2.value=data[i].content
                exampleInputPassword4.value=data[i].level
                exampleInputPassword5.value=data[i].Pinyin
                exampleInputPassword6.value=data[i].strokes
            }
        } 
    }
    var butclo=document.querySelector('#clo');
    butclo.addEventListener('click',fn5)
    function fn5(){
        divsex.style.display='none'
    }
    var tran=document.querySelector('#tran')
    tran.addEventListener('click',fn4)
    function fn4(){
        var check=document.querySelectorAll('#check');
        for(var i=0;i<check.length;i++){
            var a=check[i].checked;
            if(a){
                var exampleInputEmail2=document.querySelector('#exampleInputEmail2');
                var exampleInputPassword4=document.querySelector('#exampleInputPassword4');
                var exampleInputPassword5=document.querySelector('#exampleInputPassword5');
                var exampleInputPassword6=document.querySelector('#exampleInputPassword6');
                data[i].content=exampleInputEmail2.value 
                data[i].level=exampleInputPassword4.value
                data[i].Pinyin=exampleInputPassword5.value
                data[i].strokes=exampleInputPassword6.value
            }
        }
        divsex.style.display='none'
       render()
    }
    var divbk=document.querySelectorAll('.content-box1');
    for(var i=0;i<divbk.length;i++){
        divbk[i].onclick=function(){
            for(var i=0;i<divbk.length;i++){
                divbk[i].classList.remove('active')
            }
            this.classList.add('active')
        }
    }